
module.exports = {
  getClientIp: function(req){
    var ipAddress;
    var headers = req.headers;
    var forwardedIpsStr = headers['x-real-ip'] || headers['x-forwarded-for'];
    forwardedIpsStr ? ipAddress = forwardedIpsStr : ipAddress = null;
    if (!ipAddress) {
    ipAddress = req.connection.remoteAddress;
    }
    if (ipAddress.lastIndexOf(':') > -1) {
        ipAddress = ipAddress.slice(ipAddress.lastIndexOf(':') + 1)
    }
    return ipAddress;
  }
}
